package org.jeecg.modules.bobo.wechat.common.job;

import com.github.binarywang.wxpay.service.WxPayService;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.bobo.common.util.DateUtil;
import org.jeecg.modules.bobo.wechat.common.service.IWechatDownloadbillService;
import org.jeecg.modules.bobo.wechat.common.service.impl.WechatDownloadbillServiceImpl;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
public class DownloadbillJob implements Job {
    @Autowired
    private WxPayService wxPayService;
    @Autowired
    private IWechatDownloadbillService wechatDownloadbillService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
//        执行微信对账任务
        try {
//            WxPayBillResult wxPayBillResult = wxPayService.downloadBill(DateUtil.getTime("yyyyMMdd"),"ALL","GZIP" ,"");
//            //插入数据库
//            List<WeixinDownloadbill> weixinDownloadbills=new ArrayList<>();
//            WeixinDownloadbill weixinDownloadbill=null;
//            for (WxPayBillInfo item:
//                 wxPayBillResult.getBillInfoList()) {
//                weixinDownloadbill=new WeixinDownloadbill();
//                BeanUtils.copyProperties(item, weixinDownloadbill);
//                weixinDownloadbills.add(weixinDownloadbill);
//            }
//            weixinDownloadbillService.saveBatch(weixinDownloadbills);
            wechatDownloadbillService.getDownloadbill(DateUtil.getAfterOrPreNowTimePlus("yyyyMMdd","day",-1L));
            log.info(String.format("自动微信对账定时任务 DownloadbillJob !  时间:" + DateUtils.getTimestamp()));
        } catch (Exception e) {
            e.printStackTrace();
            log.info(String.format("自动微信对账定时任务失败 DownloadbillJob !  时间:" + DateUtils.getTimestamp()));
        }
    }
}
